<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1"><title id="oy139586">clusterdb</title><body><p id="client_util_desc">Reclusters tables that were previously clustered with <codeph>CLUSTER</codeph>.</p><section id="section2"><title>Synopsis</title><codeblock id="client_util_synopsis">clusterdb [&lt;connection-option> ...] [--verbose | -v] [--table | -t &lt;table>] [[--dbname | -d] &lt;dbname]

clusterdb [&lt;connection-option> ...] [--all | -a] [--verbose | -v]

clusterdb -? | --help

clusterdb -V | --version</codeblock></section><section id="section3"><title>Description</title><p>To cluster a table means to physically reorder a table on disk according
to an index so that index scan operations can access data on disk in
a somewhat sequential order, thereby improving index seek performance
for queries that use that index. </p><p>The <codeph>clusterdb</codeph> utility will find any tables in a database
that have previously been clustered with the <codeph>CLUSTER</codeph>
SQL command, and clusters them again on the same index that was last
used. Tables that have never been clustered are not affected. </p><p><codeph>clusterdb</codeph> is a wrapper around the SQL command <codeph>CLUSTER</codeph>.
Although clustering a table in this way is supported in Greenplum Database,
it is not recommended because the <codeph>CLUSTER</codeph> operation
itself is extremely slow. </p><p>If you do need to order a table in this way to improve your query performance,
        use a <codeph>CREATE TABLE AS</codeph> statement to reorder the table on disk
        rather than using <codeph>CLUSTER</codeph>. If you do 'cluster' a table in this way, then
          <codeph>clusterdb</codeph> would not be relevant.</p></section><section id="section4"><title>Options</title><parml><plentry><pt>-a | --all</pt><pd>Cluster all databases. </pd></plentry><plentry><pt>[-d] <varname>dbname</varname> | [--dbname=]<varname>dbname</varname></pt><pd>Specifies the name of the database to be clustered. If this is not
specified, the database name is read from the environment variable <codeph>PGDATABASE</codeph>.
If that is not set, the user name specified for the connection is used.</pd></plentry><plentry><pt>-e | --echo</pt><pd>Echo the commands that <codeph>clusterdb</codeph> generates and sends
  to the server.</pd></plentry><plentry><pt>-q | --quiet</pt><pd>Do not display a response.</pd></plentry><plentry>
          <pt>-t <varname>table</varname> | --table=<varname>table</varname></pt>
          <pd>Cluster the named table only. Multiple tables can be clustered by writing multiple
              <codeph>-t</codeph> switches. </pd></plentry><plentry><pt>-v | --verbose</pt><pd>Print detailed information during processing.</pd></plentry>
        <plentry>
          <pt>-V | --version</pt>
          <pd>Print the <codeph>clusterdb</codeph> version and exit.</pd>
        </plentry>
        <plentry>
          <pt>-? | --help</pt>
          <pd>Show help about <codeph>clusterdb</codeph> command line arguments, and exit.</pd>
        </plentry></parml><sectiondiv id="section5"><b>Connection Options</b><parml><plentry><pt>-h <varname>host</varname> | --host=<varname>host</varname></pt><pd>The host name of the machine on which the Greenplum master database
server is running. If not specified, reads from the environment variable
<codeph>PGHOST</codeph> or defaults to localhost.</pd></plentry><plentry><pt>-p <varname>port</varname> | --port=<varname>port</varname></pt><pd>The TCP port on which the Greenplum master database server is listening
for connections. If not specified, reads from the environment variable
<codeph>PGPORT</codeph> or defaults to 5432.</pd></plentry><plentry><pt>-U <varname>username</varname> | --username=<varname>username</varname></pt><pd>The database role name to connect as. If not specified, reads from
the environment variable <codeph>PGUSER</codeph> or defaults to the current
system role name.</pd></plentry><plentry><pt>-w | --no-password</pt><pd>Never issue a password prompt. If the server requires password authentication
and a password is not available by other means such as a <codeph>.pgpass</codeph>
file, the connection attempt will fail. This option can be useful in
batch jobs and scripts where no user is present to enter a password.</pd></plentry><plentry><pt>-W | --password</pt><pd>Force a password prompt.</pd></plentry>
          <plentry>
            <pt>--maintenance-db=<varname>dbname</varname></pt>
            <pd> Specifies the name of the database to connect to discover what other databases
              should be clustered. If not specified, the <codeph>postgres</codeph> database will
              be used, and if that does not exist, <codeph>template1</codeph> will be used. </pd>
          </plentry></parml></sectiondiv></section><section id="section6"><title>Examples</title><p>To cluster the database <codeph>test</codeph>:</p><codeblock>clusterdb test</codeblock><p>To cluster a single table <codeph>foo</codeph> in a database named <codeph>xyzzy</codeph>:</p><codeblock>clusterdb --table foo xyzzyb</codeblock></section><section id="section7"><title>See Also</title><p><ph><codeph>CLUSTER</codeph> in the <i>Greenplum Database Reference Guide</i></ph><ph><xref
            href="../../ref_guide/sql_commands/CLUSTER.xml#topic1"/></ph></p></section></body></topic>
